<template>
    <div>
      <el-row>
        <el-col :span="5">
          <el-input
            placeholder="请输入档案人姓名"
            v-model="likename"
            clearable>
          </el-input>
        </el-col>
      </el-row>
      <template>
        <el-table
          :data="findUsers(likename).slice((pageNun-1)*pageSize,pageNun*pageSize)"
          border
          style="width: 100%">
          <el-table-column
            prop="tMemberId"
            label="编号">
          </el-table-column>
          <el-table-column
            prop="tMember.name"
            label="操作人">
          </el-table-column>
          <el-table-column  label="体检情况">
            <template slot-scope="scope">
              <el-steps v-if="scope.row.reportStatus==0">未完成体检</el-steps>
              <el-steps v-if="scope.row.reportStatus==1">已完成体检</el-steps>
            </template>
          </el-table-column>
          <el-table-column
            prop="tMember.filenumber"
            label="档案号">
          </el-table-column>
          <el-table-column
            label="操作">
            <template slot-scope="scope">
              <el-button type="text" size="small" v-if="scope.row.reportStatus==0" @click="ck(scope.row)">开始体检</el-button>
              <el-button type="text" size="small" v-if="scope.row.reportStatus==1" @click="cks(scope.row)">查看</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          @size-change="handleSizeChange"
          :current-page.sync="pageNun"
          :page-sizes="[2,4,6]"
          :page-size='pageSize'
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </template>

      <el-dialog width="100p"  class="dialog dialogAdd" custom-class="custom-dialog"
                 :visible.sync="dm" :close-on-click-modal="false">
        <el-steps>体检报告单</el-steps>
        <el-tabs type="border-card">
          <h3>个人信息</h3>
          <el-row>
            <el-col :span="12">
              档案号:
              <el-steps>{{froms.filenumber}}</el-steps>
            </el-col>
            <el-col :span="12">
              姓名:
              <el-steps>{{froms.name}}</el-steps>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
              身份证:
              <el-steps>{{froms.idcard}}</el-steps>
            </el-col>
            <el-col :span="12">
              出生日期:
              <el-steps>{{froms.birthday | dateFormat}}</el-steps>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
              邮箱:
              <el-steps>{{froms.email}}</el-steps>
            </el-col>
            <el-col :span="12">
              手机号:
              <el-steps>{{froms.phonenumber}}</el-steps>
            </el-col>
          </el-row>
          <el-row :span="24">
            <h3>
             [{{tcname}}]</h3>
          </el-row>
          <template>
            <el-table
              :data="tableData"
              border
              style="width: 100%">
              <el-table-column
                prop="name"
                label="检查项名称">
              </el-table-column>
              <el-table-column label="结果">
                <template slot-scope="scope">
                  <input name="name"></input>
                </template>
              </el-table-column>
              <el-table-column
                prop="minck"
                label="最小参考范围">
              </el-table-column>
              <el-table-column
                prop="maxck"
                label="最大参考范围">
              </el-table-column>
            </el-table>
          </template>
          <el-button  @click="adds()" type="primary">确认</el-button>
          <el-button  @click="dm=false" type="danger">取消</el-button>
        </el-tabs>
      </el-dialog>

      <el-dialog width="100p"  class="dialog dialogAdd" custom-class="custom-dialog"
                 :visible.sync="dms" :close-on-click-modal="false">
        <el-steps>体检报告单</el-steps>
        <el-tabs type="border-card">
          <h3>个人信息</h3>
          <el-row>
            <el-col :span="12">
              档案号:
              <el-steps>{{froms.filenumber}}</el-steps>
            </el-col>
            <el-col :span="12">
              姓名:
              <el-steps>{{froms.name}}</el-steps>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
              身份证:
              <el-steps>{{froms.idcard}}</el-steps>
            </el-col>
            <el-col :span="12">
              出生日期:
              <el-steps>{{froms.birthday | dateFormat}}</el-steps>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
              邮箱:
              <el-steps>{{froms.email}}</el-steps>
            </el-col>
            <el-col :span="12">
              手机号:
              <el-steps>{{froms.phonenumber}}</el-steps>
            </el-col>
          </el-row>
          <el-row :span="24">
            <h3>[{{tcname}}]</h3>
          </el-row>
          <template>
            <el-table
              :data="tableData2"
              border
              style="width: 100%">
              <el-table-column
                prop="name"
                label="检查项名称">
              </el-table-column>
              <el-table-column
                prop="jg"
                label="结果">
              </el-table-column>
              <el-table-column
                prop="minck"
                label="最小参考范围">
              </el-table-column>
              <el-table-column
                prop="maxck"
                label="最大参考范围">
              </el-table-column>
            </el-table>
          </template>
          <el-button  @click="dms=false" type="primary">打印报告单</el-button>
          <el-button  @click="dms=false" type="danger">取消</el-button>
        </el-tabs>
      </el-dialog>
    </div>
</template>

<script>
  import  {tMemberExList,tCheckitems,tMemberExamination,tbodyckadd,tMemberExup,tbodyckid,tsetmealid} from '@/api/lgx/physical'
    export default {
      data() {
        return {
          dm: false,
          dms:false,
          cx: "",
          xx: null,
          cc:"",
          likename: "",
          pageSize: 4,
          pageNun: 1,
          total: 5,
          routerList:[],
          List: [],
          tableData:[],
          tableData2:[],
          tcname:"",
          froms:{
            id:"",
            filenumber:"",
            name:"",
            age:"",
            sex:"",
            idcard:"",
            phonenumber:"",
            password:"",
            regtime:"",
            email:"",
            birthday:"",
            remark:"",
          },
          fromjc:{
            id:"",
            tSetmealId:"",
            tMemberId:"",
            examDate:"",
            reportStatus:"",
            createtime:"",
            updatetime:""
          }
        }
      },methods:{
        handleSizeChange(val) {
          this.pageSize = val
        },findUsers(likename){
          //包含includes的意思
          return this.routerList.filter((item,i)=>{
            if(item.tMember.name.includes(likename)){
              return item;
            }
          });
        },
        ck(row){
          this.dm=true
          this.froms.id=row.tMemberId;
          this.froms.filenumber=row.tMember.filenumber;
          this.froms.name=row.tMember.name;
          this.froms.idcard=row.tMember.idcard;
          this.froms.birthday=row.tMember.birthday;
          this.froms.phonenumber=row.tMember.phonenumber;
          this.froms.email=row.tMember.email;
          this.tj(this.froms.id)
        },
        //会员检查表
        tj(id){
          tMemberExamination(id).then(response=>{
            this.fromjc.id=response.data.id;
            this.fromjc.tMemberId=response.data.tMemberId;
            this.fromjc.tSetmealId=response.data.tSetmealId;
            this.fromjc.examDate=response.data.examDate;
            this.fromjc.reportStatus=response.data.reportStatus;
            this.fromjc.createtime=response.data.createtime;
            this.fromjc.updatetime=response.data.updatetime
            this.jc(response.data.tSetmealId)
            this.tc(response.data.tSetmealId);
            this.tjs(response.data.id)
          })
        },
        //检查表查询
        jc(id){
          tCheckitems(id).then(response=> {
            this.tableData = response.data
          })
        },
        //添加体检结果表
        adds(){
          let  c=new Array();
          let gg=document.getElementsByName("name")
          let a=0;
          for(let i=0;i<gg.length;i++){
            if(gg[i].value==""){
              this.dm=true;
              this.$message.error('请把体检结果填完');
              a=1;
              break;
            }
            c.push({tMemberExaminationId:this.fromjc.id,tCheckitemId:this.tableData[i].id,jg:gg[i].value})
          }
          if(a!=1){
            this.dm=false;
            tbodyckadd(c).then(response=>{
              if(response.data==1){
                this.up();
              }
            })
          }
        },
        up(){
          this.fromjc.reportStatus=1
          tMemberExup(this.fromjc).then(response=>{
            if (response.data==1){
              this.$message({
                message: '已完成体检!',
                type: 'success'
              });
              this.sx()
            }
          })
        },
        //套餐查询
        tc(id){
          tsetmealid(id).then(response=>{
            this.tcname=response.data.name;
          })
        },
        //刷新页面
        sx(){
          tMemberExList().then(response=> {
            this.routerList = response.data
            this.total = response.data.length
          })
        },cks(row){
          this.dms=true
          this.froms.id=row.tMemberId;
          this.froms.filenumber=row.tMember.filenumber;
          this.froms.name=row.tMember.name;
          this.froms.idcard=row.tMember.idcard;
          this.froms.birthday=row.tMember.birthday;
          this.froms.phonenumber=row.tMember.phonenumber;
          this.froms.email=row.tMember.email;
          this.tj(this.froms.id)
        },
        tjs(id){
          tbodyckid(id).then(response=>{
            console.log(response.data)
            this.tableData2=response.data;
          })
        }
      },created() {
        //显示所有
        tMemberExList().then(response=> {
          this.routerList = response.data
          this.total = response.data.length
        })
      },filters:{
        dateFormat:function(data){
          var dt=new Date(data)
          var n=dt.getFullYear();
          var y=(dt.getMonth()+1).toString().padStart(2,"0");//补零操作
          var r=(dt.getDate()).toString().padStart(2,"0");
          dt.getHours();
          dt.getMinutes();
          dt.getSeconds();
          return n+"-"+y+"-"+r;
        }
      }
    }
</script>

<style scoped>

</style>
